<template>
    <div class="template-form-Lu">
        <a-modal
            title="干部职工请休假申请登记表"
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="applicationModal-form-fullmodal-Lu"
            @cancel="closeVisible">
            <div class="applicationModal-div-box-Lu">
                <div class="tabs-card-edit-box">
                    <a-tabs type="card" v-model:activeKey="summaryActiveKey" @change="summaryActiveChange">
                        <a-tab-pane key="申请表" tab="申请表"></a-tab-pane>
                        <a-tab-pane key="流转记录" tab="流转记录"></a-tab-pane>
                    </a-tabs>
                </div>
                <div  class="tab-box-v1">
                    <div v-if="summaryActiveKey == '申请表'" style="width: 70%;margin: 0 auto;padding-top: 30px;padding-bottom: 30px;">
                        <a-spin :spinning="spinning">
                            <a-button class="blue-btn" @click="printClick('请假',formState,qmImgList)" v-if="linkName == '我的已办'">打印</a-button>
                            <a-form :form="aform" ref="form" class="internalControl-reimbursement-model-form-box">
                                <a-descriptions bordered style="width: 100%;">
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            年度信息
                                        </span>
                                        <span style="line-height: 3;">{{ fndxx }}</span>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='请假申请' || linkName == '数据修订'">*</span>
                                            休假类型
                                        </span>
                                        <a-form-item ref="flglx" prop="flglx" class="zm-form-model">
                                            <a-select
                                                v-if="linkName=='请假申请' || linkName == '数据修订'"
                                                placeholder="请选择休假类型"
                                                @change="fqjlxChange"
                                                style="width: 100%;"
                                                v-decorator="[
                                                    'fqjlx', {initialValue:formState.fqjlx,rules: rules.fqjlx}]">
                                                <a-select-option
                                                v-for="(item,index) in qjlxList"
                                                :key="index"
                                                :value="item.itemValue">
                                                {{ item.itemText }}
                                                </a-select-option>
                                            </a-select>
                                            <span v-else>{{ formState.fqjlx }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='请假申请' || linkName == '数据修订'">*</span>
                                            开始日期
                                        </span>
                                        <a-form-item ref="flgsj" prop="flgsj" class="zm-form-model">
                                            <a-input-group compact v-if="linkName=='请假申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    :default-value="formState.fqjkssj"
                                                    type="date"
                                                    placeholder=""
                                                    @change="date1Change"
                                                    v-decorator="[
                                                    'fqjkssj', {initialValue:formState.fqjkssj,rules: rules.fqjkssj}]"/>
                                                <a-select
                                                    style="width: 40%"
                                                    default-value="08:00"
                                                    v-model="formState.fqjksxs"
                                                    @change="time1Change">
                                                    <a-select-option value="08:00">
                                                        08:00
                                                    </a-select-option>
                                                    <a-select-option value="12:00">
                                                        12:00
                                                    </a-select-option>
                                                    <a-select-option value="18:00">
                                                        18:00
                                                    </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fqjkssj).format('YYYY-MM-DD')}}&ensp;{{ formState.fqjksxs }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='请假申请' || linkName == '数据修订'">*</span>
                                            结束日期
                                        </span>
                                        <a-form-item ref="fhgsj" prop="fhgsj" class="zm-form-model">
                                            <a-input-group compact v-if="linkName=='请假申请' || linkName == '数据修订'">
                                                <a-date-picker
                                                    style="width: 60%"
                                                    :default-value="formState.fqjjssj"
                                                    type="date"
                                                    placeholder=""
                                                    @change="date2Change"
                                                    v-decorator="[
                                                    'fqjjssj', {initialValue:formState.fqjjssj,rules: rules.fqjjssj}]"/>
                                                    <a-select
                                                    style="width: 40%;"
                                                    default-value="18:00"
                                                    v-model="formState.fqjjsxs"
                                                    @change="time2Change">
                                                <a-select-option value="08:00">
                                                    08:00
                                                </a-select-option>
                                                <a-select-option value="12:00">
                                                    12:00
                                                </a-select-option>
                                                <a-select-option value="18:00">
                                                    18:00
                                                </a-select-option>
                                                </a-select>
                                            </a-input-group>
                                            <span v-else>{{ moment(formState.fqjjssj).format('YYYY-MM-DD')}}&emsp;{{ formState.fqjjsxs }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item>
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='离岗申请' || linkName == '数据修订'">*</span>
                                            休假天数
                                        </span>
                                        <a-form-item ref="fts" prop="fts" class="zm-form-model">
                                            <span v-if="formState.fts">{{ formState.fts }} 天</span>
                                            <span v-else>自动计算，无需填写</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item v-if="isQjsm">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='离岗申请' || linkName == '数据修订'">*</span>
                                            请假说明
                                        </span>
                                        <a-form-item ref="fqjsm" prop="fqjsm" class="zm-form-model" :key="fqjsmKey">
                                            <span style="color: red;">{{ formState.fqjsm }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item v-if="isBj">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='离岗申请' || linkName == '数据修订'">*</span>
                                            是否拿年休假抵假
                                        </span>
                                        <a-form-item ref="fsfnnxq" prop="fsfnnxq" class="zm-form-model">
                                            <a-switch
                                                v-model="formState.fsfnnxq"
                                                @change="sfnnxqChange"/>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="2">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName=='请假申请'">*</span>
                                            休假原因
                                        </span>
                                        <a-form-item ref="fyy" prop="fyy" class="zm-form-model">
                                            <a-textarea
                                                v-if="linkName=='请假申请' || linkName == '数据修订'"
                                                v-model="formState.fyy"
                                                placeholder="请输入休假原因:"
                                                :auto-size="{ minRows: 2}"
                                                v-decorator="[
                                                    'fyy', {initialValue:formState.fyy,rules: rules.fyy}]"
                                            />
                                            <span v-else>{{ formState.fyy }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            备注
                                        </span>
                                        <a-form-item class="zm-form-model">
                                            <a-input
                                                v-if="linkName == '请假申请' || linkName == '数据修订'"
                                                v-model="formState.fbz"
                                                placeholder="请输入备注"
                                                type="textarea" />
                                            <span v-else>{{ formState.fbz }}</span>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            证明材料
                                        </span>
                                        <a-form-item ref="fnbyj" prop="fnbyj" class="zm-form-model">
                                            <uploadFilesList
                                                :config="uploadFilesListConfig"
                                                @emitFormid="emitFormid"
                                                :filesFormState="{
                                                    ...formState,fqjkssj:formState.fqjkssj?moment(formState.fqjkssj).format('YYYY-MM-DD'):null,
                                                    fqjjssj:formState.fqjjssj?moment(formState.fqjjssj).format('YYYY-MM-DD'):null}"
                                            />
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('科室审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('科室审批').hjmc">*</span>
                                            科室负责人意见
                                        </span>
                                        <a-form-item ref="fksyj" prop="fksyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('科室审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffksyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('请休假',formState.fksyj,'fksyj')"
                                                    v-decorator="[
                                                        'fksyj', { initialValue:formState.fksyj, rules: rules.fksyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fksqmsj)"
                                                        :default-value="moment(formState.fksqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fksqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fksyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('科室审批')" :src="getUrl('科室审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fksqm }}</span>
                                                    <span>{{ formState.fksqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('人事审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('人事审批').hjmc">*</span>
                                            办公室审批意见
                                        </span>
                                        <a-form-item ref="frsyj" prop="frsyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('人事审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffrsyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('请休假',formState.frsyj,'frsyj')"
                                                    v-decorator="[
                                                        'frsyj', { initialValue:formState.frsyj, rules: rules.frsyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.frsqmsj)"
                                                        :default-value="moment(formState.frsqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'frsqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.frsyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('人事审批')" :src="getUrl('人事审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.frsqm }}</span>
                                                    <span>{{ formState.frsqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('分管审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('分管审批').hjmc">*</span>
                                            中心分管领导意见
                                        </span>
                                        <a-form-item ref="fksyj" prop="fksyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('分管审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsRefffgyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('请休假',formState.ffgyj,'ffgyj')"
                                                    v-decorator="[
                                                        'ffgyj', { initialValue:formState.ffgyj, rules: rules.ffgyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.ffgqmsj)"
                                                        :default-value="moment(formState.ffgqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'ffgqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.ffgyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('分管审批')" :src="getUrl('分管审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.ffgqm }}</span>
                                                    <span>{{ formState.ffgqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('中心领导审批').hjmc">
                                        <span slot="label" class="descriptions-label-slot">
                                            <span class="xhText" v-if="linkName == descriptionsData('中心领导审批').hjmc">*</span>
                                            中心主要领导意见
                                        </span>
                                        <a-form-item ref="fksyj" prop="fksyj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="(descriptionsData('中心领导审批').blzt == '待办' && linkName!=='我的已办') || linkName == '数据修订'">
                                                <reviewOpinions
                                                    ref="reviewOpinionsReffzxyj"
                                                    @getInputOpinion="getInputOpinion"
                                                    @openOpinions="opinions('请休假',formState.fzxyj,'fzxyj')"
                                                    v-decorator="[
                                                        'fzxyj', { initialValue:formState.fzxyj, rules: rules.fzxyj}
                                                ]"/>
                                                <div  v-if="linkName == '数据修订'" style="text-align: right;">
                                                    <span>办理时间：</span>
                                                    <a-date-picker
                                                        show-time
                                                        :v-model="moment(formState.fzxqmsj)"
                                                        :default-value="moment(formState.fzxqmsj)"
                                                        :allowClear="false"
                                                        @change="yjTimeChange($event,'fzxqmsj')"
                                                    />
                                                </div>
                                            </div>
                                            <div style="width: 100%;" v-else>
                                                <p>{{ formState.fzxyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('中心领导审批')" :src="getUrl('中心领导审批')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fzxqm }}</span>
                                                    <span>{{ formState.fzxqmsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('请假确认').blzt == '已办' && linkName !== '数据修订'">
                                        <span slot="label" class="descriptions-label-slot">
                                            请假确认
                                        </span>
                                        <a-form-item ref="fksfzryj" prop="fksfzryj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="descriptionsData('请假确认').blzt == '已办'">
                                                <p>{{ formState.fqrqjyj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('请假确认')" :src="getUrl('请假确认')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fqrqjr }}</span>
                                                    <span>{{ formState.fqrqjsj }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3" v-if="descriptionsData('销假确认').blzt == '已办' && linkName !== '数据修订'">
                                        <span slot="label" class="descriptions-label-slot">
                                            销假确认
                                        </span>
                                        <a-form-item ref="fksfzryj" prop="fksfzryj" class="zm-form-model">
                                            <div style="width: 100%;" v-if="descriptionsData('销假确认').blzt == '已办'">
                                                <p>{{ formState.fxjqryj }}</p>
                                                <div class="yjqm-right-bottom">
                                                    <img v-if="getUrl('销假确认')" :src="getUrl('销假确认')" alt="" class="yjqmImg"/>
                                                    <span v-else class="yjqmImg">{{ formState.fxjqrr }}</span>
                                                    <span>{{ formState.fxjqrsj }} {{ formState.fxjqrxs }}</span>
                                                </div>
                                            </div>
                                        </a-form-item>
                                    </a-descriptions-item>
                                    <a-descriptions-item :span="3">
                                        <span slot="label" class="descriptions-label-slot">
                                            注
                                        </span>
                                        <a-form-item class="zm-form-model">
                                            <p style="font-size: 16px;">
                                                1.请假1日以内(含1日)须本科室负责人审核，人事部门签署意见，
                                                报分管领导批准。请假1日以上须加报中心主任批准。<br/>
                                                2.各科室负责人请假须经由中心分管领导签署意见，中心主任批准。<br/>
                                                3.请休假审批表统一交中心办公室保存。
                                            </p>
                                        </a-form-item>
                                    </a-descriptions-item>
                                </a-descriptions>
                            </a-form>
                        </a-spin>
                    </div>
                    <div v-if="summaryActiveKey == '流转记录'" style="padding-top: 30px;">
                        <transferRecords
                            ref="transferRecordsRef"
                            :config="circulationDataTableConfig"
                            @getCirculationQmImg="getCirculationQmImg"/>
                    </div>
                </div>
            </div>
            <template slot="footer">
                <div v-if="linkName == '我的已办'">
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
                <div v-else-if="linkName == '请假确认'">
                    <a-button class="blue-btn" @click="onSubmit('提交')">确认请假</a-button>
                </div>
                <div v-else-if="linkName == '销假确认'">
                    <a-button class="blue-btn" @click="onSubmit('提交')">确认销假</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="updataData">确认修订</a-button>
                </div>
                <div v-else>
                    <a-button @click="onSave('保存')">
                        保存
                    </a-button>
                    <a-button class="blue-btn" @click="onSubmit('提交')">
                        提交
                    </a-button>
                    <a-button v-if="linkName !== '请假申请'" class="red-btn" @click="returnClick">
                        退回
                    </a-button>
                </div>
            </template>
        </a-modal>
        <printModal ref="printModalRef" />
    </div>
</template>
<script>
import {
    myndxx,
    initBzFlow,
    ocalityPostAction,
    myqxsm,
    saveFlow,
    submitFlow,
    editFuntion,
    returnUpperzdyFlowJob,
    getMoreUserSignLinkList,
    pidgetlchj,
} from './service/index'
import assessCheckApi from './service/api.js'
import transferRecords from '../modal/transferRecords'
import printModal from '../modal/printModal'
import uploadFilesList from '../modal/uploadFilesList'
import moment from 'moment'
export default {
    components: {
        transferRecords,
        printModal,
        uploadFilesList
    },
    data() {
        return {
            moment:moment,
            applicationFormVisible: false,
            summaryActiveKey: '申请表',
            aform:this.$form.createForm(this, { name: 'aform' }),
            formState: {
                fqjksxs: "08:00",
                fqjjsxs: "18:00",
                fsfnnxq : false,
                fts: 0,
            },
            circulationDataTableConfig: {
                api: assessCheckApi.flowJkPage,
                rowId: 'id',
                urlType: true,
                paramet:{
                    oaid: ''
                }
            },
            dayNum: 0,
            fndxx : "",
            qjlxList: [],
            uploadFilesListConfig: {
                isUpload: false,
                fjAddApi: assessCheckApi.initBzFlow,
            },
            rules:{
                fqjlx: [{
                    required: true,
                    message: '请选择休假类型',
                    trigger: 'blur',
                }],
                fqjkssj: [{
                    type: 'object',
                    required: true,
                    message: '请选择开始日期',
                    trigger: 'blur',
                }],
                fqjjssj: [{
                    type: 'object',
                    required: true,
                    message: '请选择结束日期',
                    trigger: 'blur',
                }],
                fyy: [{
                    required: true,
                    message: '请输入休假原因',
                    trigger: 'blur',
                }],
                fksyj: [
                    { required: true, message: '请输入本科（室）意见', trigger: 'blur' }
                ],
                frsyj: [
                    { required: true, message: '请输入办公室审批意见', trigger: 'blur' }
                ],
                ffgyj: [
                    { required: true, message: '请输入中心分管领导意见', trigger: 'blur' }
                ],
                fzxyj: [
                    { required: true, message: '请输入中心主要领导意见', trigger: 'blur' }
                ],
            },
            filesListData: [],
            qmImgList: [],
            displayList: [],
            linkName: '请假申请',
            spinning: false,
            isQjsm: false,
            isBj: false,
            fqjsmKey: '',
        }
    },
    mounted() {
        //console.log('怎么回事？111')
        this.getMyndxx()
        this.getOcalityPostAction()
        this.uploadFilesListConfig.isUpload = (this.linkName == '请假申请' || this.linkName == '数据修订')?true:false
    },
    methods: {
        getInitData(){
        //console.log('怎么回事？222')
            this.getMyndxx()
            this.formState = {}
            this.formState = {
                fqjksxs: "08:00",
                fqjjsxs: "18:00",
                fsfnnxq : false,
                fts: 0,
            }
        },
        getData(val){
            if(val){
                this.summaryActiveKey = '申请表'
                this.linkName = val.hjmc
                this.uploadFilesListConfig.isUpload = (this.linkName == '请假申请' || this.linkName == '数据修订')?true:false
                this.formState = {}
                this.formState = {
                    ...val.oaMap,
                    jobid: val.jobMap?val.jobMap.id:''
                }
                this.formState.fqjkssj = moment(val.oaMap.fqjkssj)
                this.formState.fqjjssj = moment(val.oaMap.fqjjssj)
                this.formState.fsfnnxq = val.oaMap.fsfnnxq == '是'?true:false
                this.circulationDataTableConfig.paramet.oaid = this.formState.id
                this.qmImgList = []
                this.displayList = []
                this.getDisplayList()
            }
        },
        getDisplayList(){
            pidgetlchj({pid:this.formState.id}).then((res) => {
                let arr1 = res.result
                this.displayList = []
                this.displayList = res.result

                if(this.linkName == '数据修订'){
                    const index = this.displayList.findIndex((item) => item.blzt == '待办');
                    if (index !== -1) {
                        this.displayList.splice(index, 1);
                    }
                    //console.log('this.displayList',this.displayList)
                }

                arr1.forEach(async item => {
                    if(item.blrid && item.blzt!=='待办'){
                        let resa = await getMoreUserSignLinkList({ids:item.blrid})
                        if(resa.success && resa.result.length){
                            if(resa.result[0].signLink == ''){
                                // //console.log('没有获得图片 signLink == 0')
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: null
                                })
                            } else {
                                this.qmImgList.push({
                                    hjmc: item.hjmc,
                                    url: resa.result[0].signLink+'&aa='+Date.now()
                                })
                                // //console.log('获得的签名图片列表',this.qmImgList)
                            }
                        } else {
                            // //console.log('没有获得图片')
                        }
                    } else {}
                })
                // //console.log('最终获得的签名图片列表---',this.qmImgList)
            })
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
        },
        summaryActiveChange(val){
            //console.log(val)
        },
        getMyndxx(){
            myndxx().then(res => {
              if(res.success){
                // //console.log('更新年度信息updated',res)
                if(res.result.result){
                  let data = res.result.result
                  this.dayNum = data.fnxjsyts
                  this.fndxx = "本年度可休年假：" + data.fnxjkxts + "天，" + "已休：" + data.fnxjyxts + "天，" + "剩余：" + data.fnxjsyts + "天"
                } else {
                    this.fndxx = res.result.message
                }
              }
            })
        },
        getOcalityPostAction(){
            ocalityPostAction({dictName:'OA请休假类型'}).then(res => {
                // //console.log(res)
                this.qjlxList = res.result
            })
        },
        // 休假类型
        fqjlxChange(value){
            //console.log(value)
            this.formState.fqjlx = value
            if(value == '事假' || value == '病假'){
                this.isBj = true
            } else {
                this.isBj = false
            }
            let data = {
                njdbj: this.formState.fsfnnxq,
                qxlx: this.formState.fqjlx,
                ts: this.formState.fts
            }
            myqxsm(data).then(res => {
              if(res.success){
                this.formState.fqjsm = res.result.message
                this.fqjsmKey = Date.now()
                if(this.formState.fqjsm == ''){
                  this.isQjsm = false
                } else {
                  this.isQjsm = true
                }
              }
            })
        },
        //
        date1Change(val){
            this.formState.fqjkssj = val==null?null:moment(val).format('YYYY-MM-DD')
            this.timeChange()
        },
        date2Change(val){
            this.formState.fqjjssj = val==null?null:moment(val).format('YYYY-MM-DD')
            this.timeChange()
        },
        time1Change(val){
            this.timeChange()
        },
        time2Change(val){
            this.timeChange()
        },
        timeChange(){
            //console.log('=============',this.formState.fqjkssj,this.formState.fqjjssj)
            if(this.formState.fqjkssj !== null && this.formState.fqjjssj !==null){
                let start = new Date(Date.parse(this.formState.fqjkssj));
                let end = new Date(Date.parse(this.formState.fqjjssj));
                let diff = end.getTime() - start.getTime();// 两个日期相差的毫秒数
                let days = Math.floor(diff / (1000 * 60 * 60 * 24))
                let time1 = Number(this.formState.fqjksxs.substr(0,2))
                let time2 = Number(this.formState.fqjjsxs.substr(0,2))
                let time3 = time1 + time2
                let time = 0
                if(days == 0){
                if(this.formState.fqjksxs == '08:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    this.$message.error('当前选择天数为0，请重新选择！')
                    } else if(this.formState.fqjjsxs == '12:00'){
                    time = 0.5
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 1
                    }
                } else if(this.formState.fqjksxs == '12:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    this.$message.error('当前选择天数为0，请重新选择！')
                    } else if(this.formState.fqjjsxs == '12:00'){
                    time = 0
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 0.5
                    }
                } else if(this.formState.fqjksxs == '18:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    this.$message.error('当前选择天数为0，请重新选择！')
                    } else if(this.formState.fqjjsxs == '12:00'){
                    this.$message.error('当前选择天数为0，请重新选择！')
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 0
                    }
                }
                } else {
                if(this.formState.fqjksxs == '08:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    time = 0
                    } else if(this.formState.fqjjsxs == '12:00'){
                    time = 0.5
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 1
                    }
                } else if(this.formState.fqjksxs == '12:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    time = -0.5
                    } else if(this.formState.fqjjsxs == '12:00'){
                    time = 0
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 0.5
                    }
                } else if(this.formState.fqjksxs == '18:00'){
                    if(this.formState.fqjjsxs == '08:00'){
                    if(days == 1){
                        this.$message.error('当前选择天数为0，请重新选择！')
                        time = -1
                    } else {
                        time = 0
                    }
                    } else if(this.formState.fqjjsxs == '12:00'){
                    if(days == 1){
                        time = -0.5
                    } else {
                        time = 0
                    }
                    } else if(this.formState.fqjjsxs == '18:00'){
                    time = 0
                    }
                }
                }
                let data = days + time
                if(data <= 0){
                  this.$message.warning('休假天数需大于0，当前天数为'+data+'天，请重新选择')
                  this.formState.fts = ''
                  return
                }
                if (Number(data) && data % 1 === 0 && data >= 0){
                    data = data + '.0'
                }
                this.formState.fts = data
                //console.log(this.formState.fts)
            } else {
                this.formState.fts = ''
            }
        },
        sfnnxqChange(value){
            if(value == true){
                if(this.dayNum == 0){
                    this.$message.warning('您本年度年假已休完，不能再申请年假，如有疑问请联系人事处！');
                    this.formState.fsfnnxq = false
                }
            }
        },
        emitFormid(val){
            this.formState = {
                jobid:val.jobMap.id,
                ...val.oaMap
            }
            //console.log('formState===',this.formState)
        },
        getCirculationQmImg(item1,item2){
            // //console.log('-----?????-----',item1,item2)
            this.qmImgList = []
            this.displayList = []
            this.qmImgList = item1
            this.displayList = [...item2]
            // //console.log('111111111',this.qmImgList)
            // //console.log('222222222',this.displayList)
        },
        getUrl(hjmcName){
            let url = ''
            // //console.log('没有？？？',this.qmImgList)
            this.qmImgList.forEach(item => {
                // //console.log(hjmcName,item)
                if(item.hjmc == hjmcName){
                    url = item.url
                }
            })
            // //console.log(hjmcName,url)
            return url
        },
        descriptionsData(hjmc){
            let data = {}
            this.displayList.forEach(item => {
                // //console.log('descriptionsData000',hjmc,item)
                if(item.hjmc == hjmc){
                    data = {...item}
                }
            })
            // //console.log('descriptionsData',data)
            return data
        },
        getInputOpinion(val,valueData){
            //console.log(val,valueData)
            let data = this.formState
            data[valueData.hjmc] = val
            this.aform.setFieldsValue({
                fksyj: this.formState.fksyj,
                frsyj: this.formState.frsyj,
                ffgyj: this.formState.ffgyj,
                fdwldspr: this.formState.fdwldspr
            });
        },
        opinions(val1,val2,val3){
            //console.log(val1,val2,val3)
            this.$refs[`reviewOpinionsRef${val3}`].getData({opinionType:val1,oldVal:val2,valueData:{hjmc:val3}})
        },
        onSave(){
            let data = {}
            let sdata = {
                jobid: this.formState.jobid,
                oaid: this.formState.id,
                map: {},
                opinion: '',
            }
            if(this.linkName == '请假申请'){
                data = {
                    fqjlx: this.formState.fqjlx,
                    fqjkssj: this.formState.fqjkssj?moment(this.formState.fqjkssj).format('YYYY-MM-DD'):null,
                    fqjjssj: this.formState.fqjjssj?moment(this.formState.fqjjssj).format('YYYY-MM-DD'):null,
                    fqjksxs: this.formState.fqjksxs,
                    fqjjsxs: this.formState.fqjjsxs,
                    fts: this.formState.fts.toString(),
                    fsfnnxq: this.formState.fsfnnxq == true?'是':null,
                    fyy: this.formState.fyy,
                    fbz: this.formState.fbz,
                    id: this.formState.id?this.formState.id:''
                }
                sdata.map = {
                    ...data
                }
                this.formState.id?this.saveFlowFuntion(sdata):this.initBzFlowFuntion(data)
            } else if(this.linkName == '科室审批'){
                sdata.map = {
                    fksqm: this.formState.fksqm,
                    fksqmsj: this.formState.fksqmsj,
                    fksyj: this.formState.fksyj,
                }
                sdata.opinion = this.formState.fksyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '人事审批'){
                sdata.map = {
                    frsyj: this.formState.frsyj,
                    frsqm: this.formState.frsqm,
                    frsqmsj: this.formState.frsqmsj
                }
                sdata.opinion = this.formState.frsyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '分管审批'){
                sdata.map = {
                    ffgyj: this.formState.ffgyj,
                    ffgqm: this.formState.ffgqm,
                    ffgqmsj: this.formState.ffgqmsj,
                }
                sdata.opinion = this.formState.ffgyj,
                this.saveFlowFuntion(sdata)
            } else if(this.linkName == '中心领导审批'){
                sdata.map = {
                    fzxyj: this.formState.fzxyj,
                    fzxqm: this.formState.fzxqm,
                    fzxqmsj: this.formState.fzxqmsj
                }
                sdata.opinion = this.formState.fzxyj,
                this.saveFlowFuntion(sdata)
            }
        },
        onSubmit(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data = {
                                jobid: that.formState.jobid,
                                oaid: that.formState.id,
                                map: {},
                                opinion: '',
                            }
                            if(that.linkName == '请假申请'){
                                data.map = {
                                    fqjlx: that.formState.fqjlx,
                                    fqjkssj: that.formState.fqjkssj?moment(that.formState.fqjkssj).format('YYYY-MM-DD'):null,
                                    fqjjssj: that.formState.fqjjssj?moment(that.formState.fqjjssj).format('YYYY-MM-DD'):null,
                                    fqjksxs: that.formState.fqjksxs,
                                    fqjjsxs: that.formState.fqjjsxs,
                                    fts: that.formState.fts.toString(),
                                    fsfnnxq: that.formState.fsfnnxq == true?'是':null,
                                    fyy: that.formState.fyy,
                                    fbz: that.formState.fbz,
                                    id: that.formState.id?that.formState.id:'',
                                    fsffqlc: that.formState.id?'':'是',
                                }
                                that.formState.id?that.submitFlowFuntion(data):that.initBzFlowFuntion(data.map,'1')
                            } else if(that.linkName == '科室审批'){
                                data.map = {
                                    fksqm: that.formState.fksqm,
                                    fksqmsj: that.formState.fksqmsj,
                                    fksyj: that.formState.fksyj,
                                }
                                data.opinion = that.formState.fksyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '人事审批'){
                                data.map = {
                                    frsyj: that.formState.frsyj,
                                    frsqm: that.formState.frsqm,
                                    frsqmsj: that.formState.frsqmsj
                                }
                                data.opinion = that.formState.frsyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '分管审批'){
                                data.map = {
                                    ffgyj: that.formState.ffgyj,
                                    ffgqm: that.formState.ffgqm,
                                    ffgqmsj: that.formState.ffgqmsj,
                                }
                                data.opinion = that.formState.ffgyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '中心领导审批'){
                                data.map = {
                                    fzxyj: that.formState.fzxyj,
                                    fzxqm: that.formState.fzxqm,
                                    fzxqmsj: that.formState.fzxqmsj
                                }
                                data.opinion = that.formState.fzxyj,
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '请假确认'){
                                data.map = {
                                    fqrqjyj: '确认请假',
                                    fsfqrqj: '是',
                                }
                                data.opinion = '确认请假',
                                that.submitFlowFuntion(data)
                            } else if(that.linkName == '销假确认'){
                                data.map = {
                                    fxjqryj: '确认销假',
                                }
                                data.opinion = '确认销假',
                                that.submitFlowFuntion(data)
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        initBzFlowFuntion(data,type){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.formState = {}
                    this.formState = {
                        ...res.result.oaMap,
                        jobid: res.result.jobMap.id
                    }
                    this.formState.fqjkssj = moment(this.formState.fqjkssj)
                    this.formState.fqjjssj = moment(this.formState.fqjjssj)
                    this.formState.fsfnnxq = res.result.oaMap.fsfnnxq == '是'?true:false
                    if(type){
                        this.closeVisible()
                    }
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        saveFlowFuntion(data){
            this.spinning = true
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        submitFlowFuntion(data){
            this.spinning = true
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.spinning = false
            })
        },
        // 退回
        returnClick(){
            this.aform.validateFields((err, values) => {
                if (!err) {
                    var that = this
                    that.$confirm({
                        title: '您确定要退回吗?',
                        onOk() {
                            that.spinning = true
                            queryJobByJobId({jobid:that.formState.jobid}).then(res => {
                                let list = res.result.jobHistoryList
                                let slist = list.filter(item => item.fhjmc == '请假申请')
                                const sortedDates = slist.sort((a, b) => new Date(b) - new Date(a));
                                that.returnFuntion(that.formState.jobid,sortedDates[slist.length - 1].id)
                            })
                        },
                        onCancel() {},
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审批'){
                returnStr = this.formState.fksyj
            } else if(this.linkName == '分管审批'){
                returnStr = this.formState.ffgyj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                lcmbbm: '',
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
                this.spinning = false
            })
        },
        printClick(type,value,qmValue){
            this.$refs.printModalRef.modalClick(type,value,qmValue)
        },
        yjTimeChange(val,name){
            let data = this.formState
            data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        },
        updataData(){
            var that = this
            that.$confirm({
                title: '您确定修改当前表单数据吗?',
                onOk() {
                    let data = {
                        id: that.formState.id,
                        fqjlx: that.formState.fqjlx,
                        fqjkssj: that.formState.fqjkssj?moment(that.formState.fqjkssj).format('YYYY-MM-DD'):null,
                        fqjjssj: that.formState.fqjjssj?moment(that.formState.fqjjssj).format('YYYY-MM-DD'):null,
                        fqjksxs: that.formState.fqjksxs,
                        fqjjsxs: that.formState.fqjjsxs,
                        fts: that.formState.fts.toString(),
                        fsfnnxq: that.formState.fsfnnxq == true?'是':null,
                        fyy: that.formState.fyy,
                        fbz: that.formState.fbz,
                        fksqm: that.formState.fksqm,
                        fksqmsj: that.formState.fksqmsj,
                        fksyj: that.formState.fksyj,
                        frsyj: that.formState.frsyj,
                        frsqm: that.formState.frsqm,
                        frsqmsj: that.formState.frsqmsj,
                        ffgyj: that.formState.ffgyj,
                        ffgqm: that.formState.ffgqm,
                        ffgqmsj: that.formState.ffgqmsj,
                        fzxyj: that.formState.fzxyj,
                        fzxqm: that.formState.fzxqm,
                        fzxqmsj: that.formState.fzxqmsj
                    }
                    //console.log(data)
                    that.spinning = true
                    editFuntion(data).then(res => {
                        if(res.code == 200){
                            that.$message.success(res.message)
                        } else {
                            that.$message.warning(res.message)
                        }
                        that.spinning = false
                    })
                },
                onCancel() {
                    //console.log('Cancel');
                },
            });
        },
    }
}
</script>
<style>
@import url('../css/oaLess.css');
</style>
